/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipServiceReceiveman;
import com.sasis.dao.VipServiceReceivemanDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipServiceReceivemanDaoiBatis extends BaseDaoiBATIS implements VipServiceReceivemanDao {

    /**
     * @see com.sasis.dao.VipServiceReceivemanDao#getVipServiceReceivemans(com.sasis.model.VipServiceReceiveman)
     */
    public List getVipServiceReceivemans(final VipServiceReceiveman vipServiceReceiveman) {
          return getSqlMapClientTemplate().queryForList("getVipServiceReceivemans", vipServiceReceiveman);
    }

    /**
     * @see com.sasis.dao.VipServiceReceivemanDao#getVipServiceReceiveman(Integer id)
     */
    public VipServiceReceiveman getVipServiceReceiveman(Integer id) {
        VipServiceReceiveman vipServiceReceiveman = (VipServiceReceiveman) getSqlMapClientTemplate().queryForObject("getVipServiceReceiveman", id);

//        if (vipServiceReceiveman == null) {
//            throw new ObjectRetrievalFailureException(VipServiceReceiveman.class, id);
//        }

        return vipServiceReceiveman;
    }

    /**
     * @see com.sasis.dao.VipServiceReceivemanDao#saveVipServiceReceiveman(VipServiceReceiveman vipServiceReceiveman)
     */    
    public int saveVipServiceReceiveman(final VipServiceReceiveman vipServiceReceiveman) {
        Integer id = vipServiceReceiveman.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipServiceReceiveman", vipServiceReceiveman);
        } else {
            getSqlMapClientTemplate().update("updateVipServiceReceiveman", vipServiceReceiveman);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipServiceReceiveman.class, id);
        }
        
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.VipServiceReceivemanDao#removeVipServiceReceiveman(Integer id)
     */
    public void removeVipServiceReceiveman(VipServiceReceiveman vipServiceReceiveman) {
        getSqlMapClientTemplate().update("deleteVipServiceReceiveman",  vipServiceReceiveman);
    }
}
